<template>
    <div class="login-container">
        <div class="login-content">
            <el-input
                placeholder="请输入用户名"
                v-model="username"
                clearable>
                <template slot="prepend">
                    <i class="el-icon-user font-size-c"></i>
                </template>
            </el-input>
            <div class="margin-c"></div>
            <el-input
                placeholder="请输入密码"
                v-model="password"
                show-password>
                <template slot="prepend">
                    <i class="el-icon-lock font-size-c"></i>
                </template>
            </el-input>
            <div class="margin-c"></div>
            <el-button type="primary" round :loading="loading" @click="loginHandle">登录</el-button>
        </div>
    </div>
</template>

<script>
export default {
  name: 'Login',
  data () {
    return {
      username: '',
      password: '',
      loading: false
    }
  },
  methods: {
    loginHandle () {
      let data = {
        'userName': this.username,
        'password': this.password
      }
      this.loading = true
      this.$axios({
        method: 'post',
        url: `/user/login`,
        data: this.$qs.stringify(data)
      }).then(res => {
        this.loading = false
        let data = res.data
        if (data.errorMsg) {
          this.$message.error(data.errorMsg)
        } else {
          this.$router.push('/chat')
        }
      })
    }
  }
}
</script>

<style scoped>
.login-container {
  width: 100%;
  height: 85%;
  background: white;
}
.login-content {
  position: relative;
  width: 70%;
  height: 80%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.margin-c {
  margin-top: 20px;
}
.font-size-c {
    font-size: 20px;
}
</style>
